package com.ssm.controller;

import com.ssm.service.UpdateIPService;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@Controller
@RequestMapping(value = "update")
@CrossOrigin
public class UpdateIPController {

    @Autowired
    private UpdateIPService updateIPService;
    public void setUpdateIPService(UpdateIPService updateIPService) {
        this.updateIPService = updateIPService;
    }

    //设置IP
    @RequestMapping(value = "ip")
    @ResponseBody
    public JSON updateIP(@RequestParam(value = "IP") String IP, @RequestParam(value = "address") String address){
        int i = this.updateIPService.updateIP(IP,address);
        Map map = new HashMap();
        if (i>=1){
            map.put("update","succeed");
        }else {
            map.put("update","fail");
        }

        JSONObject jsonObject = JSONObject.fromObject(map);
        return jsonObject;
    }


    //设置安全制度
    @RequestMapping(value = "Remarks")
    @ResponseBody
    public JSON updateRemarks(@RequestParam(value = "remarks") String remarks,@RequestParam(value = "address") String address){
        int i = this.updateIPService.updateRemarks(remarks,address);
        Map map = new HashMap();
        if (i>=1){
            map.put("update","succeed");
        }else {
            map.put("update","fail");
        }

        JSONObject jsonObject = JSONObject.fromObject(map);
        return jsonObject;
    }


    //设置简介
    @RequestMapping(value = "Introduction")
    @ResponseBody
    public JSON updateIntroduction(@RequestParam(value = "introduction") String introduction,@RequestParam(value = "address") String address){
        int i = this.updateIPService.updateIntroduction(introduction,address);
        Map map = new HashMap();
        if (i>=1){
            map.put("update","succeed");
        }else {
            map.put("update","fail");
        }

        JSONObject jsonObject = JSONObject.fromObject(map);
        return jsonObject;
    }

    //设置注意事项
    @RequestMapping(value = "Notice")
    @ResponseBody
    public JSON updateNotice(@RequestParam(value = "notice") String notice,@RequestParam(value = "address") String address){
        int i = this.updateIPService.updateNotice(notice,address);
        Map map = new HashMap();
        if (i>=1){
            map.put("update","succeed");
        }else {
            map.put("update","fail");
        }

        JSONObject jsonObject = JSONObject.fromObject(map);
        return jsonObject;
    }
}
